<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:fb="http://www.facebook.com/2008/fbml">
>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Together</title>
</head>
<body>
	<%@include file="header.jsp"%>
<!-- ref: https://developers.facebook.com/docs/authentication/client-side/ -->
	<script> 

		function displayUser(user) {
			var userName = document.getElementById('userName');
			var greetingText = document.createTextNode('Greetings, '
					+ user.name + '.');
			userName.appendChild(greetingText);
		}

		var appID = '119388268186376';
		if (window.location.hash.length == 0) {
			var path = 'https://www.facebook.com/dialog/oauth?';
			var queryParams = [ 'client_id=' + appID,
					'redirect_uri=' + window.location, 'response_type=token' ];
			var query = queryParams.join('&');
			var url = path + query;
			window.open(url);	
		} else {
			var accessToken = window.location.hash.substring(1);
			var path = "https://graph.facebook.com/me?";
			var queryParams = [ accessToken, 'callback=displayUser' ];
			var query = queryParams.join('&');
			var url = path + query;

			// use jsonp to call the graph
			var script = document.createElement('script');
			script.src = url;
			document.body.appendChild(script);
		}
	</script>
	<p id="userName"></p>

</body>
</html>